package so.go4.controller;

import com.alibaba.fastjson.JSON;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import so.go4.model.Article;
import so.go4.service.IArticleService;

import java.util.List;

/**
 * Created by SQB on 2015/5/25
 */
@Controller
public class IndexController{

    private static Logger logger = Logger.getLogger(IndexController.class);

    @Autowired
    IArticleService articleService;

    @RequestMapping("/index")
    public ModelAndView index(){
//        List<Article> articles = articleService.selectAllContents();
//        Article list1 = articleService.selectO("/linux");
//        logger.info(JSON.toJSONString(articles +"+++++++++++"));
        List<Article> memento = articleService.selectTitleWithCate("memento");
        List<Article> linux = articleService.selectTitleWithCate("linux");
        List<Article> java = articleService.selectTitleWithCate("java");

        logger.info(JSON.toJSONString("___--___"+memento));
//        logger.info(JSON.toJSONString(list1));
//        Iterator it = articles.iterator();
//        while(it.hasNext()){
//            System.out.println(it.next());
//        }
        ModelAndView mav = new ModelAndView("home");
        mav.addObject("memento",memento);
        mav.addObject("linux",linux);
        mav.addObject("java",java);
        return mav;
    }

}
